/*
 * @Author: szx
 * @Date: 2023-03-30 13:44:40
 * @LastEditTime: 2023-03-30 19:00:46
 * @Description: 
 * @FilePath: \learn\fullstackopen\part4\models\blog.js
 */
const mongoose = require('mongoose')


const blogSchema = new mongoose.Schema({
    title: String,
    author: String,
    url: String,
    likes: Number,
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User'
    }
})

blogSchema.set('toJSON', {
    transform: (document, returnedObject) => {
        returnedObject.id = returnedObject._id.toString()
        delete returnedObject._id
        delete returnedObject.__v
    }
})

module.exports = mongoose.model('Blog', blogSchema)
